/*
 * MembraneType.java
 *
 * Created on Feb 28, 2011, 11:38:03 AM
 *
 * Copyright (c) 2011 Artur Rataj.
 *
 * This code is distributed under the terms of the GNU Library
 * General Public License, either version 2 of the license or, at
 * your option, any later version.
 */

package pl.gliwice.iitis.spatialnn.network;

import pl.gliwice.iitis.spatialnn.network.construct.ConstructionParams;
import pl.gliwice.iitis.spatialnn.network.construct.Gaussian;

/**
 * Membrane type constants.
 */
public enum MembraneType {
    /**
     * Input membrane.
     */
    IN,
    /**
     * Output membrane.
     */
    OUT;

    /**
     * Returns the construction attributes for an output membrane. Calling
     * this function for an input membrane throws a runtime exception.
     * 
     * @return construction parameters
     */
    public ConstructionParams getConstructionParams() {
        switch(this) {
            case OUT:
                return new ConstructionParams(new Gaussian(100.0, 0.0),
                        new Gaussian(0.02, 0.002), 0.02*0.01, 0.0);
                
            default:
                throw new RuntimeException("this membrane type does not have " +
                        "construction parameters");
        }
    }
    /**
     * Returns the name, as defined in the I/O format "membrane type" string.
     * 
     * @return type name
     */
    public String getIOName() {
        switch(this) {
            case IN:
                return "in";

            case OUT:
                return "out";

            default:
                throw new RuntimeException("undefined");
        }
    }
    /**
     * Converts what <code>getIOName()</code> returns into
     * <code>MembraneType</code>.
     * 
     * @return membrane type, null if the name does not match
     */
    public static MembraneType fromIOName(String name) {
        for(MembraneType t : MembraneType.values())
            if(t.getIOName().equals(name))
                return t;
        return null;
    }
};
